package com.uuah.server.config.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import com.uuah.server.api.IUuahContext;
import com.uuah.server.api.context.IUuahContextAware;

/**
 *
 * TODO comment ...
 *
 * <p>
 * update record:updator，update time，update content and version
 * </p>
 *
 * @author <a href="jonny_quan@hotmail.com">jonny</a>
 * @date 2009 2009-3-27 下午01:25:18
 * @version 1.0.0
 */
public class UuahContextPostProcessor implements BeanPostProcessor {

	private IUuahContext uuahContext;

	public UuahContextPostProcessor(IUuahContext uuahContext) {
		this.uuahContext = uuahContext;
	}

	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		if (bean instanceof IUuahContextAware) {
			if (uuahContext == null) {
				return bean;
			}

			((IUuahContextAware) bean).setUuahContext(uuahContext);
		}
		return bean;
	}

	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		return bean;
	}

}
